package com.wave.wavesystem.business.controller;

import com.mybatisflex.core.paginate.Page;
import com.wave.wavesystem.business.pojo.dto.userRelation.UserRoleQueryRequest;
import com.wave.wavesystem.business.pojo.entity.UserEntity;
import wave.common.pojo.entity.Query;
 import wave.common.pojo.entity.Result;
import com.wave.wavesystem.business.service.UserRoleService;

import javax.annotation.Resource;

import com.wave.wavesystem.common.util.Func;
import org.springframework.web.bind.annotation.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

import java.util.List;

/**
 * @author 夕下风波
 * @date 2025-02-11
 * @description 用户-角色关联表 访问层
 */
@RestController
@RequestMapping("/userRole")
@Tag(name = "用户-角色关联接口")
public class UserRoleController {

    @Resource
    private UserRoleService userRoleService;

    /**
     * 角色批量关联用户
     *
     * @param userRoles 关联角色
     */
    @Operation(summary = "角色批量关联用户")
    @PostMapping("/batchSave")
    public Result<Boolean> batchSave(@RequestBody UserRoleQueryRequest userRoles) {
        return Result.status(userRoleService.batchSave(userRoles));
    }

    /**
     * 角色移出 用户
     *
     * @param useRoles 角色id 用户ids
     */
    @Operation(summary = "角色移出 用户")
    @PostMapping("/kickOutDept")
    public Result<Boolean> kickOutDept(@RequestBody UserRoleQueryRequest useRoles) {
        return Result.status(userRoleService.kickOutDept(useRoles));
    }

    /**
     * 获取非此角色用户
     *
     * @param roleId 角色id
     */
    @Operation(summary = "获取非此角色用户")
    @GetMapping("/notInRoleUser")
    public Result<List<UserEntity>> notInRoleUser(Long roleId) {
        return Result.data(userRoleService.notInRoleUser(roleId));
    }

    /**
     * 分页获取角色拥有的用户
     *
     * @param roleId 角色id
     * @param query  分页数据
     */
    @Operation(summary = "分页获取角色拥有的用户")
    @GetMapping("/roleUsersPage")
    public Result<Page<UserEntity>> roleUsersPage(Long roleId, Query query) {
        if (Func.isEmpty(roleId)) return Result.data(new Page<>());
        return Result.data(userRoleService.roleUsersPage(roleId, query));
    }



}